function Look(){
	var that = this;
	this._DOMAIN = document.location.protocol + "//" + document.location.host;
	this._SITE_DOMAIN = that._DOMAIN + "/appletop/rest/v1/";
	this._IS_MOBILE = true;
	this._USERAGENT = navigator.userAgent.toLowerCase();
}

var look = new Look();

$(document).ready(function(){
    /*** 初始化 ***/
});

Look.prototype._IM10184 = {//Apple排行系统 -> 国家字典
    url: look._SITE_DOMAIN + "dic/countries"
}
Look.prototype._IM10185 = {//Apple排行系统 -> 媒体类型
    url: look._SITE_DOMAIN + "dic/media_types"
}
Look.prototype._IM10186 = {//Apple排行系统 -> 国家对应的商店
    url: look._SITE_DOMAIN + "dic/stores"
}
Look.prototype._IM10187 = {//Apple排行系统 -> 商店对应的媒体类型
    url: look._SITE_DOMAIN + "dic/feed_types"
}
Look.prototype._IM10199 = {//Apple排行系统 -> 查询筛分条件
    url: look._SITE_DOMAIN + "dic/search_condition"
}
Look.prototype._IM10188 = {//Apple排行系统 -> iTunes Store排行榜 -> 获取
    url: look._SITE_DOMAIN + "get_top", 
	getJson: function(params){
		return params;
	}
}

/*** 公共请求 START ***/

/*** apple_top预请求 START ***/
	
//*************************************
//* Apple排行系统 -> 公共
//* 获取国家字典请求
//*************************************
function appleGetCountriesDictionaryRequest(){
	dataConn(look._IM10184.url, null, appleGetCountriesDictionaryCallback.Convert, null, false);
}

//*************************************
//* Apple排行系统 -> 公共
//* 获取媒体类型字典请求
//*************************************
function appleGetMediaTypesDictionaryRequest(){
	dataConn(look._IM10185.url, null, appleGetMediaTypesDictionaryCallback.Convert, null, false);
}

//*************************************
//* Apple排行系统 -> 公共
//* 获取国家对应的商店请求
//*************************************
function appleGetStoreRequest(){
	dataConn(look._IM10186.url, null, appleGetStoreCallback.Convert, null, false);
}

//*************************************
//* Apple排行系统 -> 公共
//* 获取商店对应的媒体类型请求
//*************************************
function appleGetFeedTypesRequest(){
	dataConn(look._IM10187.url, null, appleGetFeedTypesCallback.Convert, null, false);
}

//*************************************
//* Apple排行系统 -> 公共
//* 获取查询筛分条件请求
//*************************************
function appleGetSearchConditionRequest(){
	dataConn(look._IM10199.url, null, appleGetSearchConditionCallback.Convert, null, false);
}

//*************************************
//* Apple排行系统 -> iTunes Store排行榜
//* 获取请求
//*************************************
function appleGetITunesStoreTopRequest(params){
//	dataConn(look._IM10188.url, look._IM10188.getJson(params), appleGetITunesStoreTopCallback);//此方法查询过慢，废弃
	dataConn(look._IM10188.url, look._IM10188.getJson(params), appleGetTopCallback);
}
function allAppleGetITunesStoreTopRequest(params){
	var arr = eval(look.storage.get("_APPLE_TOP_SEARCH_CONDITION_DIC"));
	!look._TEMP_COUNTRY_INDEX ? Look.prototype._TEMP_COUNTRY_INDEX = 0 : null;
	var cell = $("#allAppleItunesStoreTopCell"), country = arr[look._TEMP_COUNTRY_INDEX];
	cell.css("width", parseInt(cell.children("li").outerWidth()) * (look._TEMP_COUNTRY_INDEX + 1)).append(
		'<li>' +
		'	<div class="container_title" id="containerTitle' + country + '"><p class="load_result"><img src="images/small_loader.gif"/></div>' +
		'	<div class="entry_panel" id="appleItunesStoreTopList' + country + '"></div>' +
		'</li>'
	);
	dataConn(look._IM10188.url, look._IM10188.getJson(params), allAppleGetTopCallback);
}

/*** apple_top预请求 END ***/

var initLoader = {
	
	/*** apple_top预加载 START ***/
	
	//*************************************
	//* Apple排行系统 -> iTunes Store排行榜
	//*************************************
	appleCommonFn: {
		AssaySelect: function(){
			var countriesSelect = $("#countriesSelect"), storesSelect = $("#storesSelect"), feedTypeSelect = $("#feedTypeSelect"), genreSelect = $("#genreSelect"), countryPanel = $("#countryPanel");
			for(var x in look._APPLE_TOP_COUNTRIES_DIC){
				var flag = false;
				$.each(look._APPLE_TOP_SEARCH_CONDITION_DIC.countries, function(k, o){
					if(x == o){flag = true;return false;}
				});
				if(flag){
					countryPanel.append('<a href="javascript:" key="' + x + '">' + countryDic[x] + '</a>');
				}
				//countriesSelect.append('<option value="' + x + '">' + look._APPLE_TOP_COUNTRIES_DIC[x] + '</option>');
			}
			if(look._USERAGENT.indexOf("mobile") == -1){
				look._IS_MOBILE = false;
				$("#allCountrySearchCell").show();
			}
			//[事件]
			countriesSelect.unbind("change").bind("change", function(){
				countriesChangeFn($(this).val());
				storeChangeFn(storesSelect.val());
			}).parents(".look_hidden").show();
			storesSelect.unbind("change").bind("change", function(){
				storeChangeFn($(this).val());
			});
			
			var storesAssayFn = function(storeValue){
				var storesArray = new Array();
				$.each(look._APPLE_TOP_FEED_TYPES_DIC, function(i, stores){
					if(stores.store == storeValue){
						storesArray.push(stores.translation_key);
					}
				});
				return storesArray;
			}
			var mediaTypeAssayFn = function(mediaType){
				for(var mt in look._APPLE_TOP_MEDIA_TYPES_DIC){
					if(mt == mediaType){
						return look._APPLE_TOP_MEDIA_TYPES_DIC[mt];
					}
				}
			}
			var countriesChangeFn = function(countryValue){
				storesSelect.html("").parents(".look_hidden").show();
				$.each(look._APPLE_TOP_STORE_DIC, function(i, n){
					if(n.country_code == countryValue){
						for (var x in n.stores) {
							if (n.stores[x]) {
								$.map(storesAssayFn(x), function(m){
									var flag = false;
									$.each(look._APPLE_TOP_SEARCH_CONDITION_DIC.stores, function(k, o){
										if(o == m){flag = true;return false;}
									});
									flag ? storesSelect.append('<option value="' + m + '">' + mediaTypeAssayFn(m) + '</option>') : null;
								});
							}
						}
						return false;
					}
				});
			}
			var storeChangeFn = function(storeValue){
				feedTypeSelect.html("").parents(".look_hidden").show();
				genreSelect.html("").parents(".look_hidden").show();
				$.each(look._APPLE_TOP_FEED_TYPES_DIC, function(i, n){
					if(n.translation_key == storeValue){
						$.each(n.feed_types, function(j, m){
							var flag = false;
							$.each(look._APPLE_TOP_SEARCH_CONDITION_DIC.feedTypes, function(k, o){
								if(o == m.translation_key){flag = true;return false;}
							});
							flag ? feedTypeSelect.append('<option value="' + m.translation_key + '">' + mediaTypeAssayFn(m.translation_key) + '</option>') : null;
						});
						$.each(n.subgenres, function(j, m){
							var flag = false;
							$.each(look._APPLE_TOP_SEARCH_CONDITION_DIC.genre, function(k, o){
								if(o == m.id){flag = true;return false;}
							});
							flag ? genreSelect.append('<option value="' + m.id + '"' + (m.translation_key == "games" ? " selected" : "") + '>' + mediaTypeAssayFn(m.translation_key) + '</option>') : null;
						});
					}
				});
			}
			countriesChangeFn("cn");
			storeChangeFn(storesSelect.val());
		}
	},
	appleSearchConditionLoader: function(){
		appleGetSearchConditionCallback.Check();
		appleGetMediaTypesDictionaryCallback.Check();
		appleGetFeedTypesCallback.Check();
		appleGetStoreCallback.Check();
		appleGetCountriesDictionaryCallback.Check();
		initLoader.appleCommonFn.AssaySelect();
		
		var maxDate = look.dateFormat(look.reduceDaysByDate(look.getLocalDate(), 1), "yyyy-MM-dd"),
			nowDate = look.getLocalDate();
		$("#dateInput").attr("max", nowDate).val(maxDate);
		
		//[事件]高级选项
		$("#advancedOptionsSubset").unbind("click").bind("click", function(){
			$(".options_cell").toggle();
		});
		
		//[事件]全部国家查询
		$("#allCountrySearchSubset").unbind("click").bind("click", function(){
			Look.prototype.redirectWindow = window.open("", "_blank");
			look.redirectWindow.location = "all_top.html?" + $("#optionsForm").serialize() + "&country=" + look._APPLE_TOP_SEARCH_CONDITION_DIC.countries[0] + "&first=" + $("#ifFirst").is(":checked");
		});
		
		$("#countryPanel a").unbind("click").bind("click", function(){
			Look.prototype.redirectWindow = window.open("", "_blank");
//			$.cookie("params", $("#optionsForm").serialize() + "&country=" + $(this).attr("key"));
//			$("#ifFirst").is(":checked") ? $.cookie("first", "true"): $.cookie("first", "false");
			look.redirectWindow.location = "top.html?" + $("#optionsForm").serialize() + "&country=" + $(this).attr("key") + "&first=" + $("#ifFirst").is(":checked");
		});
	},
	appleItunesStoreTopLoader : function(){
		appleGetITunesStoreTopRequest(unescape(location.search).substring(1, location.search.length));
	},
	allAppleItunesStoreTopLoader : function(){
		allAppleGetITunesStoreTopRequest(unescape(location.search).substring(1, location.search.length));
	}
	
	/*** apple_top预加载 END ***/
}

/*** apple_top Callback START ***/

//*************************************
//* Apple排行系统 -> 公共
//* 获取国家字典callback
//*************************************
var appleGetCountriesDictionaryCallback = {
	Check : function(callback){
		if(typeof(look._APPLE_TOP_COUNTRIES_DIC) == "undefined"){
			Look.prototype._APPLE_TOP_COUNTRIES_DIC = null;
		}
		look._APPLE_TOP_COUNTRIES_DIC == null ? appleGetCountriesDictionaryRequest() : typeof(callback) == "function" ? callback() : null;
	},
	Convert : function(back){
		if (back.code == 0) {
			if (back.data.feed_country && back.data.feed_country.length != 0) {
				look._APPLE_TOP_COUNTRIES_DIC = back.data.feed_country;
			} else {
				look.showInfo.error(back.code + "：国家字典数据为空");
			}
		}else{
			look.showInfo.error(back.code + ":" + back.message);
		}
	}
}

//*************************************
//* Apple排行系统 -> 公共
//* 获取媒体类型字典callback
//*************************************
var appleGetMediaTypesDictionaryCallback = {
	Check : function(callback){
		if(typeof(look._APPLE_TOP_MEDIA_TYPES_DIC) == "undefined"){
			Look.prototype._APPLE_TOP_MEDIA_TYPES_DIC = null;
		}
		look._APPLE_TOP_MEDIA_TYPES_DIC == null ? appleGetMediaTypesDictionaryRequest() : typeof(callback) == "function" ? callback() : null;
	},
	Convert : function(back){
		if (back.code == 0) {
			if (back.data && back.data.length != 0) {
				look._APPLE_TOP_MEDIA_TYPES_DIC = back.data;
			} else {
				look.showInfo.error(back.code + "：媒体类型字典数据为空");
			}
		}else{
			look.showInfo.error(back.code + ":" + back.message);
		}
	}
}

//*************************************
//* Apple排行系统 -> 公共
//* 获取国家对应的商店callback
//*************************************
var appleGetStoreCallback = {
	Check : function(callback){
		if(typeof(look._APPLE_TOP_STORE_DIC) == "undefined"){
			Look.prototype._APPLE_TOP_STORE_DIC = null;
		}
		look._APPLE_TOP_STORE_DIC == null ? appleGetStoreRequest() : typeof(callback) == "function" ? callback() : null;
	},
	Convert : function(back){
		if (back.code == 0) {
			if (back.data && back.data.length != 0) {
				look._APPLE_TOP_STORE_DIC = back.data;
			} else {
				look.showInfo.error(back.code + "：媒体类型为空");
			}
		}else{
			look.showInfo.error(back.code + ":" + back.message);
		}
	}
}

//*************************************
//* Apple排行系统 -> 公共
//* 获取商店对应的媒体类型callback
//*************************************
var appleGetFeedTypesCallback = {
	Check : function(callback){
		if(typeof(look._APPLE_TOP_FEED_TYPES_DIC) == "undefined"){
			Look.prototype._APPLE_TOP_FEED_TYPES_DIC = null;
		}
		look._APPLE_TOP_FEED_TYPES_DIC == null ? appleGetFeedTypesRequest() : typeof(callback) == "function" ? callback() : null;
	},
	Convert : function(back){
		if (back.code == 0) {
			if (back.data && back.data.length != 0) {
				look._APPLE_TOP_FEED_TYPES_DIC = back.data;
			} else {
				look.showInfo.error(back.code + "：Feed Type和类型数据为空");
			}
		}else{
			look.showInfo.error(back.code + ":" + back.message);
		}
	}
}

//*************************************
//* Apple排行系统 -> 公共
//* 获取商店对应的媒体类型callback
//*************************************
var appleGetSearchConditionCallback = {
	Check : function(callback){
		if(typeof(look._APPLE_TOP_SEARCH_CONDITION_DIC) == "undefined"){
			Look.prototype._APPLE_TOP_SEARCH_CONDITION_DIC = null;
		}
		look._APPLE_TOP_SEARCH_CONDITION_DIC == null ? appleGetSearchConditionRequest() : typeof(callback) == "function" ? callback() : null;
	},
	Convert : function(back){
		if (back.code == 0) {
			if (back.data && back.data.length != 0) {
				look._APPLE_TOP_SEARCH_CONDITION_DIC = back.data;
				look.storage.set("_APPLE_TOP_SEARCH_CONDITION_DIC", JSON.stringify(back.data.countries));
			} else {
				look.showInfo.error(back.code + "：查询筛分条件数据为空");
			}
		}else{
			look.showInfo.error(back.code + ":" + back.message);
		}
	}
}

//*************************************
//*	此方法废弃
//* Apple排行系统 -> iTunes Store排行榜
//* 获取callback
//*************************************
var appleGetITunesStoreTopCallback = function(back){
	var appleItunesStoreTopList = $("#appleItunesStoreTopList"), containerTitle = $("#containerTitle");
	appleItunesStoreTopList.html("");
	containerTitle.html("");
	if (back.code == 0) {
		if(back.data){
			$("#appleItunesStoreTopTitleCell").text(back.data.topTitle ? back.data.topTitle : "").attr("top_id", back.data.topId ? back.data.topId : "");
			if(back.data.topEntry && back.data.topEntry.length != 0){
				$.each(back.data.topEntry, function(i, list){
					var appRankHtml = "", rankFlag = false;
					if (back.data.appRank && back.data.appRank.length != 0) {
						$.each(back.data.appRank, function(j, rank){
							if (list.appId == rank.appId) {
								rankFlag = rank.appRank;
								return false;
							}
						});
					}
					if (look.getParam("first") == "true") {
						if (rankFlag) {
							return;
						}
					}
					appleItunesStoreTopList.append(
						'<div class="entry_cell" app_id="' + list.appId + '">' +
						'	<a href="' + list.appUrl + '" target="_blank">' +
						'	<div class="left">' +
						'		<div class="image_cell"><img src="' +  (list.appImage != "" ? list.appImage.split(",")[2] : "../images/no_picture.png") + '"/></div>' +
						'		<div class="number" title="当前排行">' + list.appRank + '</div>' +
						(rankFlag ? '<div class="number tag" title="历史最高排行">' + rankFlag + '</div>' : '<div class="number tag maiden" title="首次进榜">首次</div>') +
						'	</div>' +
						'	<div class="right">' +
						'		<div class="title">' + decodeURIComponent(list.appName) + '</div>' +
						'		<p><span class="label">类型：</span><span title="' + list.appCategoryLabel + '" target="_blank">' + list.appCategoryTerm + '</span></p>' +
						'		<p><span class="label">Artist：</span>' + list.appArtist + '</p>' +
						'		<p><span class="label">价格[' + list.appPriceCurrency + ']：</span>' + list.appPrice + '</p>' +
						'		<p><span class="label">数据获取日期：</span>' + list.createTime + '</p>' +
						'	</div>' +
						'	<div class="clear"></div>' +
						'	</a>' +
						'</div>'
					);
				});
				containerTitle.html(
					'<p><b class="color_yellow">' + countryDic[look.getParam("country")] + '</b>在<b class="color_yellow">' + look.getParam("updated") + '</b>共有<b class="color_yellow">' + $(".entry_cell").length + '</b>款应用' + (look.getParam("first") == "true" ? '<b class="color_green">首次</b>' : '') + '进入<b class="color_yellow">' + look.getParam("feedType") + '</b>榜。</p>'
				);
			}else{
				containerTitle.html('<div class="no_result">没有任何数据，请输入有效查询条件…</div>');
			}
		}else{
			containerTitle.html('<div class="no_result">没有任何数据，请输入有效查询条件…</div>');
		}
	}else{
		containerTitle.html('<span class="color_red">[' +back.code + "] " + back.message + "</tt>");
	}
}

//*************************************
//* Apple排行系统 -> iTunes Store排行榜
//* 获取callback
//*************************************
var appleGetTopCallback = function(back){
	var appleItunesStoreTopList = $("#appleItunesStoreTopList"), containerTitle = $("#containerTitle");
	appleItunesStoreTopList.html("");
	containerTitle.html("");
	if (back.code == 0) {
		if(back.data){
			$("#appleItunesStoreTopTitleCell").text(back.data.topTitle ? back.data.topTitle : "").attr("top_id", back.data.topId ? back.data.topId : "");
			if(back.data.topEntry && back.data.topEntry.length != 0){
				$.each(back.data.topEntry, function(i, list){
					var appRankHtml = "";
					if (look.getParam("first") == "true") {
						if (list.bestRank != 0) {
							return;
						}
					}
					appleItunesStoreTopList.append(
						'<div class="entry_cell" app_id="' + list.appId + '">' +
						'	<a href="' + list.appUrl + '" target="_blank">' +
						'	<div class="left">' +
						'		<div class="image_cell"><img src="' +  (list.appImage != "" ? list.appImage.split(",")[2] : "../images/no_picture.png") + '"/></div>' +
						'		<div class="number" title="当前排行">' + list.appRank + '</div>' +
						(list.bestRank != 0 ? '<div class="number tag" title="历史最高排行">' + list.bestRank + '</div>' : '<div class="number tag maiden" title="首次进榜">首次</div>') +
						'	</div>' +
						'	<div class="right">' +
						'		<div class="title">' + decodeURIComponent(list.appName) + '</div>' +
						'		<p><span class="label">类型：</span><span title="' + list.appCategoryLabel + '" target="_blank">' + list.appCategoryTerm + '</span></p>' +
						'		<p><span class="label">Artist：</span>' + list.appArtist + '</p>' +
						'		<p><span class="label">价格[' + list.appPriceCurrency + ']：</span>' + list.appPrice + '</p>' +
						'		<p><span class="label">数据获取日期：</span>' + list.createTime + '</p>' +
						'	</div>' +
						'	<div class="clear"></div>' +
						'	</a>' +
						'</div>'
					);
				});
				containerTitle.html(
					'<p><b class="color_yellow">' + countryDic[look.getParam("country")] + '</b>在<b class="color_yellow">' + look.getParam("updated") + '</b>共有<b class="color_yellow">' + $(".entry_cell").length + '</b>款应用' + (look.getParam("first") == "true" ? '<b class="color_green">首次</b>' : '') + '进入<b class="color_yellow">' + look.getParam("feedType") + '</b>榜。</p>'
				);
			}else{
				containerTitle.html('<div class="no_result">没有任何数据，请输入有效查询条件…</div>');
			}
		}else{
			containerTitle.html('<div class="no_result">没有任何数据，请输入有效查询条件…</div>');
		}
	}else{
		containerTitle.html('<span class="color_red">[' +back.code + "] " + back.message + "</tt>");
	}
}

var allAppleGetTopCallback = function(back){
	var arr = eval(look.storage.get("_APPLE_TOP_SEARCH_CONDITION_DIC"));
	var country = arr[look._TEMP_COUNTRY_INDEX];
	var appleItunesStoreTopList = $("#appleItunesStoreTopList" + country), containerTitle = $("#containerTitle" + country);
	containerTitle.empty();
	if (back.code == 0) {
		if(back.data){
			if(back.data.topEntry && back.data.topEntry.length != 0){
				$.each(back.data.topEntry, function(i, list){
					var appRankHtml = "";
					if (look.getParam("first") == "true") {
						if (list.bestRank != 0) {
							return;
						}
					}
					appleItunesStoreTopList.append(
						'<div class="entry_cell" app_id="' + list.appId + '">' +
						'	<a href="' + list.appUrl + '" target="_blank">' +
						'	<div class="left">' +
						'		<div class="image_cell"><img src="' +  (list.appImage != "" ? list.appImage.split(",")[2] : "../images/no_picture.png") + '"/></div>' +
						'		<div class="number" title="当前排行">' + list.appRank + '</div>' +
						(list.bestRank != 0 ? '<div class="number tag" title="历史最高排行">' + list.bestRank + '</div>' : '<div class="number tag maiden" title="首次进榜">首次</div>') +
						'	</div>' +
						'	<div class="right">' +
						'		<div class="title">' + decodeURIComponent(list.appName) + '</div>' +
						'		<p><span class="label">类型：</span><span title="' + list.appCategoryLabel + '" target="_blank">' + list.appCategoryTerm + '</span></p>' +
						'		<p><span class="label">Artist：</span>' + list.appArtist + '</p>' +
						'		<p><span class="label">价格[' + list.appPriceCurrency + ']：</span>' + list.appPrice + '</p>' +
						'		<p><span class="label">数据获取日期：</span>' + list.createTime + '</p>' +
						'	</div>' +
						'	<div class="clear"></div>' +
						'	</a>' +
						'</div>'
					);
				});
				containerTitle.html(
					'<p><b class="color_yellow">' + countryDic[country] + '</b>在<b class="color_yellow">' + look.getParam("updated") + '</b>共有<b class="color_yellow">' + appleItunesStoreTopList.children(".entry_cell").length + '</b>款应用' + (look.getParam("first") == "true" ? '<b class="color_green">首次</b>' : '') + '进入<b class="color_yellow">' + look.getParam("feedType") + '</b>榜。</p>'
				);
			}else{
				containerTitle.html('<div class="no_result">没有任何数据，请输入有效查询条件…</div>');
			}
		}else{
			containerTitle.html('<div class="no_result">没有任何数据，请输入有效查询条件…</div>');
		}
	}else{
		containerTitle.html('<span class="color_red">[' +back.code + "] " + back.message + "</tt>");
	}
		
	look._TEMP_COUNTRY_INDEX++;
	if(look._TEMP_COUNTRY_INDEX != arr.length - 1){
		console.log(unescape(location.search).substring(1, location.search.length).replace("country=" + look.getParam("country"), "country=" + arr[look._TEMP_COUNTRY_INDEX]))
		allAppleGetITunesStoreTopRequest(unescape(location.search).substring(1, location.search.length).replace("country=" + look.getParam("country"), "country=" + arr[look._TEMP_COUNTRY_INDEX]));
	}
}

//*************************************
//* Apple排行系统 -> 应用详细信息
//* 获取callback
//*************************************
var appleGetAppContentCallback = function(back){
	var popAppContentCell = $("#popAppContentCell");
	if (back.code == 0) {
		if (back.data && back.data != "") {
			popAppContentCell.html(decodeURIComponent(back.data).replace(/[(\r)]/g, "<br/>"));
			$.positionDiv();
		}else{
			popAppContentCell.html('<div class="no_result">没有任何数据，请输入有效查询条件…</div>');
		}
	}else{
		look.showInfo.error(back.code + ":" + back.message);
	}
}

/*** apple_top Callback END ***/

/**
 * 提示信息
 */
Look.prototype.showInfo = {
    add: function(text){
        alert(text);
    },
    right: function(text){
        this.add(text);
    },
    error: function(text){
        this.right(text);
    }
}

/**
 * 获取指定的URL参数值
 * @param {String} paramName URL参数
 * @param {String} from 来源
 * @return paramValue URL参数值
 */
Look.prototype.getParam = function(paramName){
    var paramValue = "";
    var isFound = false;
    if (location.search.indexOf("?") == 0 && location.search.indexOf("=") > 1) {
        var arrSource = unescape(location.search).substring(1, location.search.length).split("&");
        i = 0;
        while (i < arrSource.length && !isFound) {
            if (arrSource[i].indexOf("=") > 0) {
                if (arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase()) {
                    paramValue = arrSource[i].split("=")[1];
                    isFound = true;
                }
            }
            i++;
        }
    }
    return paramValue;
}

/**
 * 日期格式化
 * "yyyy-MM-dd"
 * @param {Object} date
 * @param {Object} format
 */
Look.prototype.dateFormat = function(date, format){
    var o = {
        "M+": date.getMonth() + 1, //month
        "d+": date.getDate(), //day
        "h+": date.getHours(), //hour
        "m+": date.getMinutes(), //minute
        "s+": date.getSeconds(), //second
        "q+": Math.floor((date.getMonth() + 3) / 3), //quarter
        "S": date.getMilliseconds() //millisecond
    }
    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
}

/**
 * 获取本地日期
 * @return 2012-06-02
 */
Look.prototype.getLocalDate = function(){
    var $date = new Date(), $y = $date.getFullYear(), $m = $date.getMonth() + 1, $d = $date.getDate();
    if ($m < 10) {
        $m = "0" + $m;
    }
    if ($d < 10) {
        $d = "0" + $d;
    }
    return $y + "-" + $m + "-" + $d;
}

/**
 * 指定日期减去天数
 * @param {Object} date
 * @param {Object} num
 */
Look.prototype.reduceDaysByDate = function(date, num){
    return new Date(Date.parse(date) - (86400000 * num));
}

Look.prototype.storage = {
    init: function(){
        try {
            return 'localStorage' in window && window['localStorage'] !== null;
        } catch (e) {
            return false;
        }
    },
    get: function(key){
        if (this.init()) {
            return localStorage.getItem(key);
        }
    },
    set: function(key, value){
        if (this.init()) {
            localStorage.setItem(key, value);
        }
    }
}

/**
 * 数据请求方法
 * @param requestData
 * @param httpHeader
 * @param responseFn
 * @return
 */
function dataConn(url, requestData, responseFn, completeFn, async){
    $.ajax({
        type: "POST",
        url: url,
        dataType: "text",
        data: (requestData == null ? '' : requestData + '&') + 'un01=dreamingame',
        timeout: 15000,
        async: (async != undefined ? async : true),
        beforeSend: function(XMLHttpRequest){
        },
        success: function(data, textStatus, XMLHttpRequest){
            var back = eval('(' + data + ')');
            if (back.code == "302") {
                look.showInfo.error(back.code + "：非法登录，正在为您跳转……");
                location.href = back.message;
                return false;
            }
            if (back != null) {
                if (back.code == 9001 || back.code == 403) {
      				look.showInfo.error(back.code + " : " + back.message + " [" + url + "]");
                    return false;
                }
                if (typeof(responseFn) == "function") {
                    try {
                        eval(responseFn(back, textStatus));
                    } catch (e) {
                        look.showInfo.error("[ERROR] name : " + e.name + ", message: " + e.message);
                    }
                }
            } else {
                look.showInfo.error("网络连接出错！");
            }
        },
        error: function(XMLHttpRequest, error){
            if (error == "timeout") {
                look.showInfo.error("请求超时：请求系统返回数据超时！请稍候再试吧…");
            } else {
                look.showInfo.error(error + "：返回数据可能为非JSON格式…");
            }
        },
        complete: function(XMLHttpRequest, textStatus){
            if (completeFn != undefined && completeFn != null) {
                try {
                    eval(completeFn(textStatus));
                } catch (e) {
                	look.showInfo.error("[ERROR] name : " + e.name + ", message: " + e.message);
                }
            }
        }
    });
}